package cn.com.nes.site.controller.product;

import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.entity.vo.product.ProductFieldsConfigVO;
import cn.com.nes.site.service.product.ProductFieldsConfigService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 产品参数字段维护
 *      -- 参数：制热量、制冷量、额定功率、...
 *
 * @Author: ShenWei
 * @Date: 2024/03/27/16:26F
 */
@Controller
@RequestMapping("/v2/product/fields")
public class ProductFieldsConfigController {
    @Resource
    ProductFieldsConfigService productFieldsConfigService;

    /**
     * 按设备类型查询字段配置详情
     */
    @RequestMapping(value = "/getFieldsConfig",method = RequestMethod.GET)
    @ResponseBody
    public PageData getFieldsConfig(ProductFieldsConfigVO vo){
        String equipmentTypeId = vo.getEquipmentTypeId(); // 设备类型id
        if (StrUtil.isBlank(equipmentTypeId)){
            return PageData.error("设备类型id不能为空");
        }
        return productFieldsConfigService.getFieldsConfig(equipmentTypeId);
    }


    /**
     * 保存设备类型查询字段配置详情 - 单条字段配置
     */
    @RequestMapping(value = "/saveFieldsConfig",method = RequestMethod.POST)
    @ResponseBody
    public PageData saveFieldsConfig(@RequestBody ProductFieldsConfigVO vo){
        return productFieldsConfigService.saveFieldsConfig(vo);
    }


    /**
     * 删除字段配置
     */
    @RequestMapping(value = "/delFieldsConfig",method = RequestMethod.POST)
    @ResponseBody
    public PageData delFieldsConfig(@RequestBody ProductFieldsConfigVO vo){
        return productFieldsConfigService.delFieldsConfig(vo);
    }


    /**
     * 复制字段配置
     */
    @RequestMapping(value = "/copyFieldsConfig",method = RequestMethod.POST)
    @ResponseBody
    public PageData copyFieldsConfig(@RequestBody ProductFieldsConfigVO vo){
        return productFieldsConfigService.copyFieldsConfig(vo);
    }
}
